package dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.List;

import dao.AreaDao;
import dao.BaseDao;
import dao.Mapper;
import entity.Area;

public class AreaDaoImpl extends BaseDao implements AreaDao {

	private Mapper<Area> mapper = new Mapper<Area>() {

		@Override
		public Area doMapper(ResultSet rs) throws Exception {
			Area a = new Area();
			a.setId(rs.getInt("id"));
			a.setName(rs.getString("name"));
			return a;
		}
	};

	public AreaDaoImpl(Connection con) {
		super(con);
	}

	@Override
	public List<Area> findAll() {
		return query("select * from area", mapper);
	}

	@Override
	public int deleteArea(int id) {
		return update("delete from area where id = ?", id);
	}

	@Override
	public List<Area> findCityByPId(int id) {
		return query("select * from area where parent_id = ?", mapper, id);
	}

	@Override
	public List<Area> findByPage(int start, int pageSize) {
		return query("select * from area order by id limit ?,?", mapper,start,pageSize);
	}

}
